let sh = 0; // 每次滚动的距离
Component({
    /**
     * 组件的属性列表
     */
    properties: {
        isShow: Boolean,
        lyrics: String
    },
    lifetimes: {
        ready() {
            wx.getSystemInfo({
                success: (result) => {
                    // console.log("系统信息：", result);
                    sh = result.screenWidth / 750 * 64;
                },
            })
        }
    },
    observers: {
        lyrics(lyr) {
            // console.log(lyr);
            this.parseLyric(lyr)
        }
    },

    /**
     * 组件的初始数据
     */
    data: {
        list: [],
        active: -1,
        scrollTop: 0
    },

    /**
     * 组件的方法列表
     */
    methods: {
        update(time) {
            // console.log("兄弟组件收到currentTime:", time);
            let list = this.data.list;
            for (let i = 0; i < list.length; i++) {
                if (time <= list[i].time) {
                    this.setData({
                        active: i - 1,
                        scrollTop: (i - 1) * sh
                    });
                    break;
                }
            }
        },
        parseLyric(template) {
            let container = template.split("\n");
            console.log("歌词是：", container);
            let list = [];
            container.forEach(row => {
                let res = /\[(\d{2,}):(\d{2,})\.(\d{1,3})\](.*)/.exec(row);
                if (res !== null) {
                    const second = parseInt(res[1]) * 60 + parseInt(res[2]) + parseInt(res[3]) / 1000;
                    list.push({
                        time: second,
                        lyric: res[4]
                    })
                }
            })
            this.setData({
                list
            })
        }
    }
})